<?php
namespace app\api\controller;

use think\Db;
class Index
{
      public function change_caoliu(){
            $redis = new \Redis();
            $redis->connect('127.0.0.1', 6379);
            $redis->auth('si1OCDvrr4WitsVi');
            

            $length = $redis->lsize('post_id_cl_list');

            $data=[];
            for($i=0;$i<$length;$i++){
                  $id = $redis->rpop('post_id_cl_list');
                  if(!$id){
                        break;
                  }
                  $arr = $redis->hgetall('c'.$id);
                  if($arr){
                    $redis->del('c'.$id);
                    $uid = Db::name('caoliujishu')->where(['urlid'=>$id])->value('id');
                    if(!$uid){
                      $data=[ 'content'=>$arr['content'],
                              'title'=>$arr['title'],
                              'url'=>$arr['url'],
                              'date'=>$arr['time'],
                              'urlid'=>$id,
                          ];
                      Db::name('caoliujishu')->insert($data);
                    } 
                  }
                  
                  echo $id."\n";
            }
            
            
    }


    public function change_novel(){
            $redis = new \Redis();
            $redis->connect('127.0.0.1', 6379);
            $redis->auth('si1OCDvrr4WitsVi');
            

            $length = $redis->lsize('post_id_novel_list');
            
            $data=[];
            for($i=0;$i<$length-10;$i++){
                  $id = $redis->rpop('post_id_novel_list');
                  if(!$id){
                        break;
                  }
                  $arr = $redis->hgetall('n'.$id);
                  if($arr){
                    $redis->del('n'.$id);
                    $uid = Db::name('caoliujishu')->where(['urlid'=>$id])->value('id');
                    if(!$uid){
                      $data=[ 'content'=>$arr['content'],
                              'title'=>$arr['title'],
                              'url'=>$arr['url'],
                              'date'=>$arr['time'],
                              'urlid'=>$id,
                          ];
                      Db::name('caoliujishu')->insert($data);
                    } 
                  }
                  
                  echo $id."\n";
            }
            
            
    }


}	